﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using NS_QuangCaoTiepThiBUS;

namespace NS_QuangCaoTiepThi
{
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LayDanhSachNoiDungTinTucNoiBat();

                LayDanhSachNoiDungTinTucChung();

                TaoVideoList();
            }
        }

        private void TaoVideoList()
        {
            String strJwplyer = String.Empty;
            strJwplyer  = "<script type='text/javascript'>";
            strJwplyer += "jwplayer(\"leftContent2\").setup({ flashplayer: \"/Scripts/player.swf\", playlist: [";
            NoiDungBUS noidungBUS = new NoiDungBUS();
            IList<NoiDung> lstNoiDung = noidungBUS.LayDanhSachVideo();
            foreach (NoiDung n in lstNoiDung)
            {
                strJwplyer += " { file: \"./QCTT/Videos/" + n.TenFileVideoNoiBo + "\" },";
            }

            strJwplyer = strJwplyer.Substring(0, strJwplyer.Length - 1);
            strJwplyer += "],";
            strJwplyer += "height: 560, width: 780, autostart: \"true\", repeat: \"always\", shuffle: \"false\", controlbar: \"none\" });";
            strJwplyer += "</script>";

            leftContent2.InnerHtml = strJwplyer;
        }

        protected void LayDanhSachNoiDungTinTucNoiBat()
        {
            NoiDungBUS ndBUS = new NoiDungBUS();

            IList<NoiDung> lstNoiDung = ndBUS.LayDanhSachNoiDungTinTucNoiBat();
            dlstTinTucTrongNgay.RepeatColumns = lstNoiDung.Count;
            dlstTinTucTrongNgay.DataSource = ndBUS.LayDanhSachNoiDungTinTucNoiBat();
            dlstTinTucTrongNgay.DataBind();
        }

        protected void LayDanhSachNoiDungTinTucChung()
        {
            NoiDungBUS ndBUS = new NoiDungBUS();

            gvTinTucChung.DataSource = ndBUS.LayDanhSachNoiDungTinTucNoiBat();
            gvTinTucChung.DataBind();
        }

        protected void btnDangNhap_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/DangNhap.aspx");
        }
    }
}